package com.wcy.controller;

import com.wcy.domain.SysMenu;
import com.wcy.model.R;
import com.wcy.model.RolePrivilegesParam;
import com.wcy.service.SysRolePrivilegeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>Title:SysRolePrivilegeController.java</p >
 * <p>Description: </p >
 * <p>Copyright: 公共服务与应急管理战略业务本部 Copyright(c)2020</p >
 * <p>Date:2021/9/20 16:34</p >
 *
 * @author wcy (wangchaoyanga@mail.taiji.com.cn)
 * @version 1.0
 */
@Api(tags = "角色权限的配置")
@RestController
public class SysRolePrivilegeController {

    @Autowired
    private SysRolePrivilegeService sysRolePrivilegeService;

    @GetMapping("/roles_privileges")
    @ApiOperation(value = "查询角色的权限列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId",value = "角色的ID")
    })
    public R<List<SysMenu>> findSysMenAndPrivileges(Long roleId){
        List<SysMenu> sysMenus=sysRolePrivilegeService.findSysMenAndPrivileges(roleId);
        return R.ok(sysMenus);
    }

    @PostMapping("/grant_privileges")
    @ApiOperation(value = "授予角色某种权限")
    public R grantPrivileges(@RequestBody RolePrivilegesParam rolePrivilegesParam){
        boolean isOk=sysRolePrivilegeService.grantPrivileges(rolePrivilegesParam);
        if(isOk){
            return R.ok();
        }
        return R.fail("授予失败");
    }
}
